<script type="text/javascript">
    function load_form(url)
    {        
        $.ajax(
        {
            url: url,
            type: 'GET',
            error: function()
            {
                alert('Error !');
            },
            success: function(success)
            {
                $("#div_action").html(success);
	    }
	});
    }

    function load_list_all(url)
    {
        $.ajax(
        {
            url: url,
	    type: 'GET',
	    error: function()
            {
                alert('Error !');
	    },
	    success: function(success)
	    {
                $("#list_all").html(success);
	    }
	});
    }

    function add_ajax()
    {
        if($('#username').val()==""){ show_error('div_message', "Tên đăng nhập không được rỗng!"); return;}
        if($('#password').val()==""){ show_error('div_message', "Mật khẩu không được rỗng!"); return;}
		$.ajax(
        {
            url: '<?php echo base_url_admin("user/add")?>',
	    type: 'POST',
	    data: $('#form_user').serialize(),
	    error: function()
            {
                alert('Error !');
	    },
	    success: function(success)
	    {
                if(success=="yes")
                {
                    show_success('div_message',"Thêm người dùng thành công!");
                    load_list_all('<?php echo base_url_admin("user/list_users");?>');
	        }
	     }
	 });
      }

      function edit_ajax()
      {
          if($('#username').val()==""){ show_error('div_message', "Tên đăng nhập không được rỗng!"); return;}
	  	  $.ajax(
          {
                url: '<?php echo base_url_admin("user/edit")?>',
	        type: 'POST',
	        data: $('#form_user').serialize(),
	        error: function()
                {
	            alert('Error !');
	        },
	        success: function(success)
	        {		        
                if(success=="yes")
                {
	        		show_success('div_message',"Sửa thông tin thành công!");
	        		load_list_all('<?php echo base_url_admin("user/list_users");?>');	        	
                }
	        }
	   });
       }

       function change_status(url,mode,user_id)
       {
           var p = '';
           p = p + 'mode='+mode;
	   p = p + '&user_id='+user_id;
           $.ajax(
           {
               url: url,
	       type: 'POST',
	       data:p,
	       error: function()
               {
                   alert('Error !');
	       },
	       success: function(success)
	       {
                    load_list_all('<?php echo base_url_admin("user/list_users");?>');              	        	
	       }
	    });
        }

        function del_user(url)
        {
            if(!confirm('Bạn có chắc muốn xóa người dùng này?'))
            {            
                return;
            }
            $.ajax(
            {
	        url: url,
	        type: 'GET',
	        error: function()
                {
	            alert('Error !');
	        },
	        success: function(msg)
	        {
                    load_list_all('<?php echo base_url_admin("user/list_users");?>');
	        }
	    });
        }
</script>
<div id="list_all">
<div class="mainright">
    <form method="post" id="form_order" name="form_order">
	<h1>Quản lý người dùng</h1>
    <div class="toppage">
    	<span class="left">
            <font class="number">(<?php echo $this->user_model->get_count_all_user();?>)</font>
            <a href="javascript:;">Người dùng</a><font class="line">|</font>
            <font class="number">(<?php echo $this->user_model->get_count_all_user('yes');?>)</font>
            <a href="javascript:;"><font color="#0b9901">Kích hoạt</font></a><font class="line">|</font>
            <font class="number">(<?php echo $this->user_model->get_count_all_user('no');?>)</font>
            <a href="javascript:;"><font color="#c60001">Chưa kích hoạt</font></a>
        </span>
        <span class="right">            
            <input type="button" onclick="load_form('<?php echo base_url_admin("user/add");?>');document.getElementById('div_action').style.display='block';document.getElementById('fade').style.display='block'" value="Thêm người dùng" style="cursor: pointer;font-family:Arial; text-decoration: none;">
        </span>
    </div>
    <div class="tableout">
        <div class="title1">
            <div class="column" style="width:2%;"></div>
            <div class="column" style="width:50%;">Tên đăng nhập</div>
            <div class="column" style="width:30%;">Email</div>
            <div class="column" style="width:10%;" align="center">Trạng thái</div>
        </div>
        <?php 
        foreach($all_users as $num => $user):
		$role = "Gold";
		if($user->roleid==1){
			$role = "Diamond";
		}
         ?>
	         <div class="linecate">
	        	<div class="column" sttyle="width:2%;"><input type="checkbox" name="event_id[]" id="event_id[]" value="<?php echo $user->userid?>" /></div>
	            <div class="column" style="width:50%;" onmouseover="Hovercat('<?php echo $num?>')" onmouseout="Outcat('<?php echo $num?>')">
	            	<a href="javascript:void(0)" class="menu<?php echo $num?>" onclick ="load_form('<?php echo base_url_admin("user/edit/".$user->userid);?>');document.getElementById('div_action').style.display='block';document.getElementById('fade').style.display='block'"><h2><?php echo $user->user?></h2></a><br />
	                <div class="action" id="neocat-<?php echo $num?>">
	                    <img src="<?php echo admin_img("edit.gif")?>" /><a href="javascript:void(0)" onclick ="load_form('<?php echo base_url_admin("user/edit/".$user->userid);?>');document.getElementById('div_action').style.display='block';document.getElementById('fade').style.display='block'">Sửa</a>|
	                    
                          <?php if($user->status=='no'){?>
	                      <img src="<?php echo admin_img("active.png")?>" class="png" /><a href="javascript:;" onclick="change_status('<?php echo base_url_admin("user/change_status")?>','yes',<?php echo $user->userid?>);">Kích hoạt</a>
	                      <?php }else{?>
	                      <img src="<?php echo admin_img("unactive.png")?>" class="png" /><a href="javascript:;" onclick="change_status('<?php echo base_url_admin("user/change_status")?>','no',<?php echo $user->userid?>);">Hủy kích hoạt</a>
	                     <?php }?>
	                     <img src="<?php echo admin_img("delete.gif")?>" class="png" /><a href="javascript:;" onclick="del_user('<?php echo base_url_admin("user/del/".$user->userid)?>');">Xóa</a>
	                    
	                </div>
	            </div>	            
	            <div class="column" style="width:30%;color:#2195C8;"><?php echo $user->mail?></div>
	            <div class="column" style="width:10%;"  align="center">
	           <?php if($user->status=='yes'){?>
	                      <a href="javascript:;" onclick="change_status('<?php echo base_url_admin("user/change_status")?>','no',<?php echo $user->userid?>);"><img src="<?php echo admin_img("active.png")?>" class="png" /></a>
	                      <?php }else{?>
	                      <a href="javascript:;" onclick="change_status('<?php echo base_url_admin("user/change_status")?>','yes',<?php echo $user->userid?>);"><img src="<?php echo admin_img("unactive.png")?>" class="png" /></a>
	            <?php }?>
	            </div>
	        </div>
     
         <input type="hidden" name="user[<?php echo $num?>][id]" value="<?php echo $user->userid?>" />
        <?php endforeach; echo "</div>"; //last div close ?>
        </form>
    </div>
    
</div>
</div><!-- end list all -->
<!-- form category action -->
<div id="div_action" class="white_content"><!-- Content action ajax --></div>
<div id="fade" class="black_overlay"></div>
<!-- end form category action -->